% This program gathers the data of reversals (rev/sec and duration)and omegas(ome/sec and duration) 
% from all the different experiments 
% The data of all individuals is then stored in a final matrix; from
% the final matrix creates graphs for the different measures

load ('/Users/anapereira/Dropbox/Matlab/data analyzis group/reversals and omegas scripts/labels/revandomecount_group.mat');%matrix to store the data

load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/RRF3_exp5_ZC2834_F1/reversals and omegas all/RRF3_Exp5_ZC2834_all_reversals_and_omegas_F1.mat');
load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/RRF3_exp6_ZC2834_F1/reversals and omegas all/RRF3_Exp6_ZC2834_all_reversals_and_omegas_F1.mat');
load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/RRF3_exp7_ZC2834_F1/reversals and omegas all/RRF3_Exp7_ZC2834_all_reversals_and_omegas_F1.mat');
load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/RRF3_exp8_ZC2834_F1/reversals and omegas all/RRF3_Exp8_ZC2834_all_reversals_and_omegas_F1.mat');
load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/RRF3_exp9_ZC2834_F1/reversals and omegas all/RRF3_Exp9_ZC2834_all_reversals_and_omegas_F1.mat');
load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/RRF3_exp11_ZC2834_F1/reversals and omegas all/RRF3_Exp11_ZC2834_all_reversals_and_omegas_F1.mat');
load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/RRF3_exp16_ZC2834_F1/reversals and omegas all/RRF3_Exp16_ZC2834_all_reversals_and_omegas_F1.mat');
load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/RRF3_exp30_ZC2834_F1/reversals and omegas all/RRF3_Exp30_ZC2834_all_reversals_and_omegas_F1.mat');
%load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/MT_STM7_OP vs PA F1/rev and omegas all/MT_STM7_all_reversals_and_omegas_F1.mat');
%load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/MT_STM8_OP vs PA F1/rev and omegas all/MT_STM8_all_reversals_and_omegas_F1.mat');
%load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/MT_STM9_OP vs PA F1/rev and omegas all/MT_STM9_all_reversals_and_omegas_F1.mat');
%load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/MT_STM10_OP vs PA F1/rever and omegas all/MT_STM10_all_reversals_and_omegas_F1.mat');
%load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/MT_STM12_OP vs PA F1/rever and omegas all/MT_STM12_all_reversals_and_omegas_F1.mat');
%load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/MT_STM13_OP vs PA F1/rever and omegas all/MT_STM13_all_reversals_and_omegas_F1.mat');
%load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/MT_STM14_OP vs PA F1/rever and omegas all/MT_STM14_all_reversals_and_omegas_F1.mat');
%load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/MT_STM15_OP vs PA F1/rever and omegas all/MT_STM15_all_reversals_and_omegas_F1.mat');
%load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/MT_STM16_OP vs PA F1/rever and omegas all/MT_STM16_all_reversals_and_omegas_F1.mat');
%load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/MT_STM17_OP vs PA F1/rever and omegas all/MT_STM17_all_reversals_and_omegas_F1.mat');
%load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/MT_STM19_OP vs PA F1/rever and omegas all/MT_STM19_all_reversals_and_omegas_F1.mat');
%load ('/Users/anapereira/Dropbox/Matlab/data/matlab data/MT_STM21_OP vs PA F1/reversals and omegas all/MT_STM21_all_reversals_and_omegas_F1.mat');

A1 = RRF3_Exp5_ZC2834_all_reversals_and_omegas_F1;
A2 = RRF3_Exp6_ZC2834_all_reversals_and_omegas_F1;
A3 = RRF3_Exp7_ZC2834_all_reversals_and_omegas_F1;
A4 = RRF3_Exp8_ZC2834_all_reversals_and_omegas_F1;
A5 = RRF3_Exp9_ZC2834_all_reversals_and_omegas_F1;
A6 = RRF3_Exp11_ZC2834_all_reversals_and_omegas_F1;
A7 = RRF3_Exp16_ZC2834_all_reversals_and_omegas_F1;
A8 = RRF3_Exp30_ZC2834_all_reversals_and_omegas_F1;
%A9 = MT_STM7_all_reversals_and_omegas_F1;
%A10 = MT_STM8_all_reversals_and_omegas_F1;
%A11 = MT_STM9_all_reversals_and_omegas_F1;
%A12 = MT_STM10_all_reversals_and_omegas_F1;
%A13 = MT_STM12_all_reversals_and_omegas_F1;
%A14 = MT_STM13_all_reversals_and_omegas_F1;
%A15 = MT_STM14_all_reversals_and_omegas_F1;
%A16 = MT_STM15_all_reversals_and_omegas_F1;
%A17 = MT_STM16_all_reversals_and_omegas_F1;
%A18 = MT_STM17_all_reversals_and_omegas_F1;
%A19 = MT_STM19_all_reversals_and_omegas_F1;
%A20 =  MT_STM21_all_reversals_and_omegas_F1;

%concatenate the different matrixes
reversals_omegas_count_multiarray = cat(3, A1, A2, A3, A4, A5, A6, A7, A8); %if want to separate experiments specify here; save this file

%extract data to new matrix
nexp = size (reversals_omegas_count_multiarray, 3);%number of experiments to go throuth the different experiments

rev_ome_joinexperiments_all = [];%if want to separate experiments specify here

rev_ome_data_multiarray_all = {};% if separate exeriments separate here

%% Reversals/sec 

% OP to OP rev/minute
rev_secOPtoOP_exp = [];
rev_secOPtoOP_ind = [];

for i=1:nexp
    rev_secOPtoOP_exp = reversals_omegas_count_multiarray {2,2,i};
    ind = size (rev_secOPtoOP_exp, 1);
    for j =1:ind
        rev_secOPtoOP_ind_loop = rev_secOPtoOP_exp (j)*60; %reversals per min
        rev_secOPtoOP_ind = [rev_secOPtoOP_ind;rev_secOPtoOP_ind_loop];% colects all the values of average reversals independently of experiment
    end
end

revandomeganalyzis_together {2,2} = rev_secOPtoOP_ind; 

% OP to PA rev
rev_secOPtoPA_exp = [];
rev_secOPtoPA_ind = [];

for i=1:nexp
    rev_secOPtoPA_exp = reversals_omegas_count_multiarray {2,3,i};
    ind = size (rev_secOPtoPA_exp, 1);
    for j =1:ind
        rev_secOPtoPA_ind_loop = rev_secOPtoPA_exp (j)*60;
        rev_secOPtoPA_ind = [rev_secOPtoPA_ind;rev_secOPtoPA_ind_loop];
    end
end

revandomeganalyzis_together {2,3} = rev_secOPtoPA_ind; 

% OP progeny rev
rev_sec_OPprogeny = [rev_secOPtoOP_ind;rev_secOPtoPA_ind ];
revandomeganalyzis_together {2,18} = rev_sec_OPprogeny; 

% PA to OP rev/sec
rev_secPAtoOP_exp = [];
rev_secPAtoOP_ind = [];

for i=1:nexp
    rev_secPAtoOP_exp = reversals_omegas_count_multiarray {2,4,i};
    ind = size (rev_secPAtoOP_exp, 1);
    for j =1:ind
        rev_secPAtoOP_ind_loop = rev_secPAtoOP_exp (j)*60;
        rev_secPAtoOP_ind = [rev_secPAtoOP_ind;rev_secPAtoOP_ind_loop];
    end
end

revandomeganalyzis_together {2,4} = rev_secPAtoOP_ind; 

% PA to PA rev/sec
rev_secPAtoPA_exp = [];
rev_secPAtoPA_ind = [];

for i=1:nexp
    rev_secPAtoPA_exp = reversals_omegas_count_multiarray {2,5,i};
    ind = size (rev_secPAtoPA_exp, 1);
    for j =1:ind
        rev_secPAtoPA_ind_loop = rev_secPAtoPA_exp (j)*60;
        rev_secPAtoPA_ind = [rev_secPAtoPA_ind;rev_secPAtoPA_ind_loop];
    end
end

revandomeganalyzis_together {2,5} = rev_secPAtoPA_ind; 

% PA progeny rev/sec
rev_sec_PAprogeny = [rev_secPAtoOP_ind;rev_secPAtoPA_ind ];
revandomeganalyzis_together {2,19} = rev_sec_PAprogeny; 
%% Reversal duration 

% OP to OP rev/duration
rev_durOPtoOP_exp = [];
rev_durOPtoOP_ind = [];

for i=1:nexp
    rev_durOPtoOP_exp = reversals_omegas_count_multiarray {2,6,i};
    ind = size (rev_durOPtoOP_exp, 1);
    for j =1:ind
        rev_durOPtoOP_ind_loop = rev_durOPtoOP_exp (j);
        rev_durOPtoOP_ind = [rev_durOPtoOP_ind;rev_durOPtoOP_ind_loop];
    end
end

revandomeganalyzis_together {2,6} = rev_durOPtoOP_ind; 

% OP to PA rev/duration
rev_durOPtoPA_exp = [];
rev_durOPtoPA_ind = [];

for i=1:nexp
    rev_durOPtoPA_exp = reversals_omegas_count_multiarray {2,7,i};
    ind = size (rev_durOPtoPA_exp, 1);
    for j =1:ind
        rev_durOPtoPA_ind_loop = rev_durOPtoPA_exp (j);
        rev_durOPtoPA_ind = [rev_durOPtoPA_ind;rev_durOPtoPA_ind_loop];
    end
end

revandomeganalyzis_together {2,7} = rev_durOPtoPA_ind; 

% OP progeny rev/duration
rev_duration_OPprogeny = [rev_durOPtoOP_ind;rev_durOPtoPA_ind];
revandomeganalyzis_together {2,20} = rev_duration_OPprogeny; 

% PA to OP rev/duration
rev_durPAtoOP_exp = [];
rev_durPAtoOP_ind = [];

for i=1:nexp
    rev_durPAtoOP_exp = reversals_omegas_count_multiarray {2,8,i};
    ind = size (rev_durPAtoOP_exp, 1);
    for j =1:ind
        rev_durPAtoOP_ind_loop = rev_durPAtoOP_exp (j);
        rev_durPAtoOP_ind = [rev_durPAtoOP_ind;rev_durPAtoOP_ind_loop];
    end
end

revandomeganalyzis_together {2,8} = rev_durPAtoOP_ind; 

% PA to PA rev/duration
rev_durPAtoPA_exp = [];
rev_durPAtoPA_ind = [];

for i=1:nexp
    rev_durPAtoPA_exp = reversals_omegas_count_multiarray {2,9,i};
    ind = size (rev_durPAtoPA_exp, 1);
    for j =1:ind
        rev_durPAtoPA_ind_loop = rev_durPAtoPA_exp (j);
        rev_durPAtoPA_ind = [rev_durPAtoPA_ind;rev_durPAtoPA_ind_loop];
    end
end

revandomeganalyzis_together {2,9} = rev_durPAtoPA_ind; 

% PA progeny rev/duration
rev_duration_PAprogeny = [rev_durPAtoOP_ind;rev_durPAtoPA_ind];
revandomeganalyzis_together {2,21} = rev_duration_PAprogeny; 
%% Omegas/second 

% Op to OP omegas/min
ome_secOPtoOP_exp = [];
ome_secOPtoOP_ind = [];

for i=1:nexp
    ome_secOPtoOP_exp = reversals_omegas_count_multiarray {2,14,i};
    ind = size (ome_secOPtoOP_exp, 1);
    for j =1:ind
        ome_secOPtoOP_ind_loop = ome_secOPtoOP_exp (j)*60;
        ome_secOPtoOP_ind = [ome_secOPtoOP_ind;ome_secOPtoOP_ind_loop];
    end
end

revandomeganalyzis_together {2,10} = ome_secOPtoOP_ind; 

% OP to PA omegas/min
ome_secOPtoPA_exp = [];
ome_secOPtoPA_ind = [];

for i=1:nexp
    ome_secOPtoPA_exp = reversals_omegas_count_multiarray {2,15,i};
    ind = size (ome_secOPtoPA_exp, 1);
    for j =1:ind
        ome_secOPtoPA_ind_loop = ome_secOPtoPA_exp (j)*60;
        ome_secOPtoPA_ind = [ome_secOPtoPA_ind;ome_secOPtoPA_ind_loop];
    end
end

revandomeganalyzis_together {2,11} = ome_secOPtoPA_ind; 

% OP progeny omegas/min
ome_second_OPprogeny = [ome_secOPtoOP_ind;ome_secOPtoPA_ind];
revandomeganalyzis_together {2,22} = ome_second_OPprogeny; 

% PA to OP omegas/sec
ome_secPAtoOP_exp = [];
ome_secPAtoOP_ind = [];

for i=1:nexp
    ome_secPAtoOP_exp = reversals_omegas_count_multiarray {2,16,i};
    ind = size (ome_secPAtoOP_exp, 1);
    for j =1:ind
        ome_secPAtoOP_ind_loop = ome_secPAtoOP_exp (j)*60;
        ome_secPAtoOP_ind = [ome_secPAtoOP_ind;ome_secPAtoOP_ind_loop];
    end
end

revandomeganalyzis_together {2,12} = ome_secPAtoOP_ind; 

% PA to PA omegas/min
ome_secPAtoPA_exp = [];
ome_secPAtoPA_ind = [];

for i=1:nexp
    ome_secPAtoPA_exp = reversals_omegas_count_multiarray {2,17,i};
    ind = size (ome_secPAtoPA_exp, 1);
    for j =1:ind
        ome_secPAtoPA_ind_loop = ome_secPAtoPA_exp (j)*60;
        ome_secPAtoPA_ind = [ome_secPAtoPA_ind;ome_secPAtoPA_ind_loop];
    end
end

revandomeganalyzis_together {2,13} = ome_secPAtoPA_ind; 

% PA progeny omegas/min
ome_second_PAprogeny = [ome_secPAtoOP_ind;ome_secPAtoPA_ind];
revandomeganalyzis_together {2,23} = ome_second_PAprogeny; 

% OP to OP ome/duration
ome_durOPtoOP_exp = [];
ome_durOPtoOP_ind = [];

for i=1:nexp
    ome_durOPtoOP_exp = reversals_omegas_count_multiarray {2,18,i};
    ind = size (ome_durOPtoOP_exp, 1);
    for j =1:ind
        ome_durOPtoOP_ind_loop = ome_durOPtoOP_exp (j);
        ome_durOPtoOP_ind = [ome_durOPtoOP_ind;ome_durOPtoOP_ind_loop];
    end
end

revandomeganalyzis_together {2,14} = ome_durOPtoOP_ind; 

% OP to PA ome/duration
ome_durOPtoPA_exp = [];
ome_durOPtoPA_ind = [];

for i=1:nexp
    ome_durOPtoPA_exp = reversals_omegas_count_multiarray {2,19,i};
    ind = size (ome_durOPtoPA_exp, 1);
    for j =1:ind
        ome_durOPtoPA_ind_loop = ome_durOPtoPA_exp (j);
        ome_durOPtoPA_ind = [ome_durOPtoPA_ind;ome_durOPtoPA_ind_loop];
    end
end

revandomeganalyzis_together {2,15} = ome_durOPtoPA_ind; 

% OP progeny ome/duration
ome_duration_OPprogeny = [ome_durOPtoOP_ind;ome_durOPtoPA_ind];
revandomeganalyzis_together {2,24} = ome_duration_OPprogeny; 

% PA to OP ome/duration
ome_durPAtoOP_exp = [];
ome_durPAtoOP_ind = [];

for i=1:nexp
    ome_durPAtoOP_exp = reversals_omegas_count_multiarray {2,20,i};
    ind = size (ome_durPAtoOP_exp, 1);
    for j =1:ind
        ome_durPAtoOP_ind_loop = ome_durPAtoOP_exp (j);
        ome_durPAtoOP_ind = [ome_durPAtoOP_ind;ome_durPAtoOP_ind_loop];
    end
end

revandomeganalyzis_together {2,16} = ome_durPAtoOP_ind;

% PA to PA ome/duration
ome_durPAtoPA_exp = [];
ome_durPAtoPA_ind = [];

for i=1:nexp
    ome_durPAtoPA_exp = reversals_omegas_count_multiarray {2,21,i};
    ind = size (ome_durPAtoPA_exp, 1);
    for j =1:ind
        ome_durPAtoPA_ind_loop = ome_durPAtoPA_exp (j);
        ome_durPAtoPA_ind = [ome_durPAtoPA_ind;ome_durPAtoPA_ind_loop];
    end
end

revandomeganalyzis_together {2,17} = ome_durPAtoPA_ind;

% PA progeny ome/duration
ome_duration_PAprogeny = [ome_durPAtoOP_ind;ome_durPAtoPA_ind];
revandomeganalyzis_together {2,25} = ome_duration_PAprogeny; 
%% Analyzis of normality

for j=2:25
    data = revandomeganalyzis_together {2,j,1};
    sujeitos = size (data,1);
     if sujeitos >= 3 % each individual comes with one value for reversals
     [H, p, W] = swtest(data, 0.05);%null hypothesis data comes from normal distribuition; if h=1 reject null hypothesis that data comes from a normal distribuition
     elseif sujeitos ==2 
     p = NaN;
     elseif sujeitos ==1 
     p = NaN;
     elseif sujeitos ==0
     p= NaN;
     end
    revandomeganalyzis_together {3,j,1} = p;
end


for k=2:25
    data = revandomeganalyzis_together {2,k,1};
    media = mean (data);
    revandomeganalyzis_together {4,k,1} = media;
end

for l=2:25
    data = revandomeganalyzis_together {2,l,1};
    desviopadrao = std (data);
    revandomeganalyzis_together {5,l,1} = desviopadrao;
end

for m=2:25
    data = revandomeganalyzis_together {2,m,1};
    numberworms = size (data,1);% not really number of worms but number of events - if rev/sec is number of worms but if rev durantion is the number of reverses
    revandomeganalyzis_together {6,m,1} = numberworms;
end

for n = 2:25
    desviopadrao = revandomeganalyzis_together {5,n,1};
    numberworms = revandomeganalyzis_together {6,n,1};
    sem = desviopadrao./ (sqrt(numberworms));
    revandomeganalyzis_together {7,n,1} = sem;
end

for o = 2:25
    data = revandomeganalyzis_together {2,o,1};
    mediana = median (data);
    revandomeganalyzis_together {8,o,1} = mediana;
end

for p = 2:25
    data = revandomeganalyzis_together  {2,p,1};
    primeiroq = quantile(data,0.25);
    revandomeganalyzis_together  {9,p,1} = primeiroq;
end

for q = 2:25
    data = revandomeganalyzis_together  {2,q,1};
    terceiroq = quantile(data,0.75);
    revandomeganalyzis_together  {10,q,1} = terceiroq;
end

%% Create box plots for Reversal/sec
rev_secOPOP = revandomeganalyzis_together {2,2,1};
rev_secOPPA = revandomeganalyzis_together {2,3,1};
rev_secPAOP = revandomeganalyzis_together {2,4,1};
rev_secPAPA = revandomeganalyzis_together {2,5,1};

reversalsfrOPOP = size (rev_secOPOP, 1);
reversalsfrOPPA = size (rev_secOPPA, 1);
reversalsfrPAOP = size (rev_secPAOP, 1);
reversalsfrPAPA = size (rev_secPAPA, 1);

B1 = zeros (reversalsfrOPOP,1);
 for i = 1:reversalsfrOPOP
     B1 (i,1)= 0;
 end

B2 = zeros (reversalsfrOPPA,1);
 for i = 1:reversalsfrOPPA
     B2 (i,1)= 1;
 end

B3 = zeros (reversalsfrPAOP,1);
 for i = 1:reversalsfrPAOP
     B3 (i,1)= 2;
 end
 
B4 = zeros (reversalsfrPAPA,1);
 for i = 1:reversalsfrPAPA
     B4 (i,1)= 3;
 end 
    
%Create the boxplots 
figure
data = [rev_secOPOP; rev_secOPPA; rev_secPAOP;rev_secPAPA];
group = [ B1; B2; B3; B4];
boxplot (data, group, 'Labels',{'OPOP','OPPA', 'PAOP', 'PAPA'}, 'ColorGroup', [.6 1 .6;.4 .6 .6;.6 .4 .6;.2 0 .4]);
title ('Reversals per second')
ylabel ('Reversals/sec','FontSize',14);
ylim ([ 0,3]);

%Matrix = {rev_secOPOP,rev_secOPPA,rev_secPAOP,rev_secPAPA};

%mc:color of the bars indicating the mean
%medc: color of the bars indicating the mean
% bw is based on the values of the probability distribuition therefore in
% how may separation we want in the grid; function kde (in other functions)
% is a way to compute it more accurately; for now use value of 0.005 but we
% all data analyze implement this function
%figure
%violin (Matrix,'facecolor',[.6 1 .6;.4 .6 .6;.6 .4 .6;.2 0 .4],'edgecolor','none','bw',0.005,'mc','w','medc','b')
%ylabel('Reversal/sec','FontSize',14)
%title ('Reversals per second')
%ylim ([ 0,0.1 ]);

% Create box plots for OP and PA progeny Reversal/sec
rev_secOPprogeny = revandomeganalyzis_together {2,18,1};
rev_secPAprogeny = revandomeganalyzis_together {2,19,1};

reversalsfrOPprog = size (rev_secOPprogeny, 1);
reversalsfrPAprog = size (rev_secPAprogeny, 1);

B1 = zeros (reversalsfrOPprog,1);
 for i = 1:reversalsfrOPprog
     B1 (i,1)= 0;
 end

B2 = zeros (reversalsfrPAprog,1);
 for i = 1:reversalsfrPAprog
     B2 (i,1)= 1;
 end
 
 %Create the boxplots 
figure
data = [rev_secOPprogeny; rev_secPAprogeny];
group = [ B1; B2];
boxplot (data, group, 'Labels',{'OPprogeny','PAprogeny'}, 'ColorGroup', [.6 1 .6;.4 .6 .6]);
title ('Reversals per second')
ylabel ('Reversals/sec','FontSize',14);
ylim ([ 0,3 ]);

Matrix = {rev_secOPprogeny,rev_secPAprogeny};

%mc:color of the bars indicating the mean
%medc: color of the bars indicating the mean
% bw is based on the values of the probability distribuition therefore in
% how may separation we want in the grid; function kde (in other functions)
% is a way to compute it more accurately; for now use value of 0.005 but we
% all data analyze implement this function
figure
violin (Matrix,'facecolor',[.6 1 .6;.2 0 .4],'edgecolor','none','bw',0.005,'mc','w','medc','b')
ylabel('Reversal/sec','FontSize',14)
title ('Reversals per second')
ylim ([ 0,3 ]);

%% Create Box Plots for reversals duration
rev_durOPOP = revandomeganalyzis_together {2,6,1};
rev_durOPPA = revandomeganalyzis_together {2,7,1};
rev_durPAOP = revandomeganalyzis_together {2,8,1};
rev_durPAPA = revandomeganalyzis_together {2,9,1};

%Create the boxplots 
reversalsOPOP = size (rev_durOPOP, 1);
reversalsOPPA = size (rev_durOPPA, 1);
reversalsPAOP = size (rev_durPAOP, 1);
reversalsPAPA = size (rev_durPAPA, 1);

B5 = zeros (reversalsOPOP,1);
 for i = 1:reversalsOPOP
     B5 (i,1)= 0;
 end

B6 = zeros (reversalsOPPA,1);
 for i = 1:reversalsOPPA
     B6 (i,1)= 1;
 end

B7 = zeros (reversalsPAOP,1);
 for i = 1:reversalsPAOP
     B7 (i,1)= 2;
 end
 
B8 = zeros (reversalsPAPA,1);
 for i = 1:reversalsPAPA
     B8 (i,1)= 3;
 end 

figure
data2 = [rev_durOPOP; rev_durOPPA; rev_durPAOP;rev_durPAPA];
group2 = [ B5; B6; B7; B8];
boxplot (data2, group2, 'Labels',{'OPOP','OPPA', 'PAOP', 'PAPA'}, 'ColorGroup', [.6 1 .6;.4 .6 .6;.6 .4 .6;.2 0 .4]);
title ('Reversals duration')
ylabel ('Duration (sec)','FontSize',14);
ylim ([ 0, 7]);

%Matrix2 = {rev_durOPOP,rev_durOPPA,rev_durPAOP,rev_durPAPA}; 

%figure
%violin (Matrix2,'facecolor',[.6 1 .6;.4 .6 .6;.6 .4 .6;.2 0 .4],'edgecolor','none','bw',0.4,'mc','w','medc','b')
%title ('Reversals duration')
%ylabel('Duration (sec)','FontSize',14)

% Create box plots for OP and PA progeny Reversal/duration
rev_durOPprogeny = revandomeganalyzis_together {2,20,1};
rev_durPAprogeny = revandomeganalyzis_together {2,21,1};

reversalsdurOPprog = size (rev_durOPprogeny, 1);
reversalsdurPAprog = size (rev_durPAprogeny, 1);

B1 = zeros (reversalsdurOPprog,1);
 for i = 1:reversalsdurOPprog
     B1 (i,1)= 0;
 end

B2 = zeros (reversalsdurPAprog,1);
 for i = 1:reversalsdurPAprog
     B2 (i,1)= 1;
 end
 
%Create the boxplots 
figure
data = [rev_durOPprogeny; rev_durPAprogeny];
group = [ B1; B2];
boxplot (data, group, 'Labels',{'OPprogeny','PAprogeny'}, 'ColorGroup', [.6 1 .6;.4 .6 .6]);
title ('Reversals duration')
ylabel ('Reversals/sec','FontSize',14);
ylim ([ 0, 7]);

Matrix = {rev_durOPprogeny,rev_durPAprogeny};

%mc:color of the bars indicating the mean
%medc: color of the bars indicating the mean
% bw is based on the values of the probability distribuition therefore in
% how may separation we want in the grid; function kde (in other functions)
% is a way to compute it more accurately; for now use value of 0.005 but we
% all data analyze implement this function
figure
violin (Matrix,'facecolor',[.6 1 .6;.2 0 .4],'edgecolor','none','bw',0.05,'mc','w','medc','b')
ylabel('Reversal duration','FontSize',14)
title ('Reversals duration')
ylim ([ 0, 7]);


%% Create Box Plots for omegas per second
ome_secOPOP = revandomeganalyzis_together {2,10,1};
ome_secOPPA = revandomeganalyzis_together {2,11,1};
ome_secPAOP = revandomeganalyzis_together {2,12,1};
ome_secPAPA = revandomeganalyzis_together {2,13,1};

%Create the boxplots 
omegasfrOPOP = size (ome_secOPOP, 1);
omegasfrOPPA = size (ome_secOPPA, 1);
omegasfrPAOP = size (ome_secPAOP, 1);
omegasfrPAPA = size (ome_secPAPA, 1);

B9 = zeros (omegasfrOPOP,1);
 for i = 1:omegasfrOPOP
     B9 (i,1)= 0;
 end

B10 = zeros (omegasfrOPPA,1);
 for i = 1:omegasfrOPPA
     B10 (i,1)= 1;
 end

B11 = zeros (omegasfrPAOP,1);
 for i = 1:omegasfrPAOP
     B11 (i,1)= 2;
 end
 
B12 = zeros (omegasfrPAPA,1);
 for i = 1:omegasfrPAPA
     B12 (i,1)= 3;
 end 
 
figure
data3 = [ome_secOPOP; ome_secOPPA; ome_secPAOP;ome_secPAPA];
group3 = [ B9; B10; B11; B12];
boxplot (data3, group3, 'Labels',{'OPOP','OPPA', 'PAOP', 'PAPA'}, 'ColorGroup', [.6 1 .6;.4 .6 .6;.6 .4 .6;.2 0 .4]);
title ('Omegas per second')
ylabel ('Omegas/sec','FontSize',14);
ylim ([ 0, 3]);

%Matrix3 = {ome_secOPOP, ome_secOPPA, ome_secPAOP, ome_secPAPA}; 

%figure
%violin (Matrix3,'facecolor',[.6 1 .6;.4 .6 .6;.6 .4 .6;.2 0 .4],'edgecolor','none','bw',0.005,'mc','w','medc','b')
%title ('Omegas per second')
%ylabel('Omegas/sec','FontSize',14)

% Create box plots for OP and PA progeny Omegas/sec
ome_secOPprogeny = revandomeganalyzis_together {2,22,1};
ome_secPAprogeny = revandomeganalyzis_together {2,23,1};

omegasfrOPprog = size (ome_secOPprogeny, 1);
omegasfrPAprog = size (ome_secPAprogeny, 1);

B1 = zeros (omegasfrOPprog,1);
 for i = 1:omegasfrOPprog
     B1 (i,1)= 0;
 end

B2 = zeros (omegasfrPAprog,1);
 for i = 1:omegasfrPAprog
     B2 (i,1)= 1;
 end
 
%Create the boxplots 
figure
data = [ome_secOPprogeny; ome_secPAprogeny];
group = [ B1; B2];
boxplot (data, group, 'Labels',{'OPprogeny','PAprogeny'}, 'ColorGroup', [.6 1 .6;.4 .6 .6]);
title ('Omegas per second')
ylabel ('Omegas/sec','FontSize',14);
ylim ([ 0, 3]);

Matrix = {ome_secOPprogeny,ome_secPAprogeny};

%mc:color of the bars indicating the mean
%medc: color of the bars indicating the mean
% bw is based on the values of the probability distribuition therefore in
% how may separation we want in the grid; function kde (in other functions)
% is a way to compute it more accurately; for now use value of 0.005 but we
% all data analyze implement this function
figure
violin (Matrix,'facecolor',[.6 1 .6;.2 0 .4],'edgecolor','none','bw',0.005,'mc','w','medc','b')
ylabel('Omegas/sec','FontSize',14)
title ('Omegas per second')
ylim ([ 0, 3]);


%% Create Box Plots for omegas duration
ome_durOPOP = revandomeganalyzis_together {2,14,1};
ome_durOPPA = revandomeganalyzis_together {2,15,1};
ome_durPAOP = revandomeganalyzis_together {2,16,1};
ome_durPAPA = revandomeganalyzis_together {2,17,1};

%Create the boxplots 
omegasOPOP = size (ome_durOPOP, 1);
omegasOPPA = size (ome_durOPPA, 1);
omegasPAOP = size (ome_durPAOP, 1);
omegasPAPA = size (ome_durPAPA, 1);

B13 = zeros (omegasOPOP,1);
 for i = 1:omegasOPOP
     B13 (i,1)= 0;
 end

B14 = zeros (omegasOPPA,1);
 for i = 1:omegasOPPA
     B14 (i,1)= 1;
 end

B15 = zeros (omegasPAOP,1);
 for i = 1:omegasPAOP
     B15 (i,1)= 2;
 end
 
B16 = zeros (omegasPAPA,1);
 for i = 1:omegasPAPA
     B16 (i,1)= 3;
 end 
 
figure
data4 = [ome_durOPOP; ome_durOPPA; ome_durPAOP;ome_durPAPA];
group4 = [ B13; B14; B15; B16];
boxplot (data4, group4, 'Labels',{'OPOP','OPPA', 'PAOP', 'PAPA'}, 'ColorGroup', [.6 1 .6;.4 .6 .6;.6 .4 .6;.2 0 .4]);
title ('Omegas duration')
ylabel('Duration (sec)','FontSize',14)
ylim ([ 0, 7 ]);

%Matrix4 = {ome_durOPOP, ome_durOPPA, ome_durPAOP, ome_durPAPA}; 

%figure
%violin (Matrix4,'facecolor',[.6 1 .6;.4 .6 .6;.6 .4 .6;.2 0 .4],'edgecolor','none','bw',0.4,'mc','w','medc','b')
%title ('Omegas duration')
%ylabel('Omegas (sec)','FontSize',14)

% Create box plots for OP and PA progeny Omegas/duration
ome_durOPprogeny = revandomeganalyzis_together {2,24,1};
ome_durPAprogeny = revandomeganalyzis_together {2,25,1};

omegasdurOPprog = size (ome_durOPprogeny, 1);
omegasdurPAprog = size (ome_durPAprogeny , 1);

B1 = zeros (omegasdurOPprog,1);
 for i = 1:omegasdurOPprog
     B1 (i,1)= 0;
 end

B2 = zeros (omegasdurPAprog,1);
 for i = 1:omegasdurPAprog
     B2 (i,1)= 1;
 end
 
%Create the boxplots 
figure
data = [ome_durOPprogeny; ome_durPAprogeny];
group = [ B1; B2];
boxplot (data, group, 'Labels',{'OPprogeny','PAprogeny'}, 'ColorGroup', [.6 1 .6;.4 .6 .6]);
title ('Omegas duration')
ylabel ('Omegas duration','FontSize',14);
ylim ([ 0, 7]);

Matrix = {ome_durOPprogeny,ome_durPAprogeny};

%mc:color of the bars indicating the mean
%medc: color of the bars indicating the mean
% bw is based on the values of the probability distribuition therefore in
% how may separation we want in the grid; function kde (in other functions)
% is a way to compute it more accurately; for now use value of 0.005 but we
% all data analyze implement this function
figure
violin (Matrix,'facecolor',[.6 1 .6;.2 0 .4],'edgecolor','none','bw',0.05,'mc','w','medc','b')
ylabel('Omegas duration','FontSize',14)
title ('Omegas duration')
ylim ([ 0,7]);


rev_ome_data_multiarray_all_ZC2834_13_11_2019 = reversals_omegas_count_multiarray; % change name to save 

rev_ome_joinexperiments_all_ZC2834_13_11_2019 = revandomeganalyzis_together; % change name to save
















